package eu.news.template;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import eu.jk.base.io.Texter;
import eu.jk.helper.RootPath;
import eu.news.data.hibernate.pojo.HB_News;

public class NewsStatic {
	static String dir=RootPath.root+"../statics/";
	
	public static void deleteData(int id){
		File file=new File(dir+id);
		if(file.exists())
			file.delete();
	}
	
	public static String updateData(HB_News news,HttpServletRequest request) throws IOException{
		deleteData(news.getId());
		String page=WebPageHelper.news(news, request);
		Texter writer = new Texter(dir+news.getId());
		writer.overWrite(page);
		return page;
	}
	
	
	public static String readData(int id) throws IOException{
		return Texter.readText(dir+id,"UTF-8");
	}
	
	public static boolean exists(int id){
		File file=new File(dir+id);
		return file.exists();
	}
	
}
